<template>
    <div>
        <el-tag type="info" v-if="user && user.name">{{ user.name }}</el-tag>
    </div>
</template>
<script>
import { getUser } from '@/api/user';
export default {
    data() {
        return {
            user: {
                id: null,
                name: null,
            }
        }
    },
    methods: {
        getData() {
            if (!this.id)
                return;
            getUser(this.id).then(res => {
                this.user = res || {};
            })
        }
    },
    watch: {
        id: {
            handler(value) {
                if (!value) {
                    this.user = {};
                    return;
                }
                this.getData();
            }
        }
    },
    mounted() {

    },
    props: {
        id: {
            type: String,
            default: null
        }
    }
}
</script>